package com.gok.seasonmovie.mapper;

import com.gok.seasonmovie.entity.Booking;
import com.gok.seasonmovie.entity.Movie;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface BookingMapper {


    @Select("SELECT * FROM movies where id in (SELECT mid FROM booking WHERE cid = #{id})")
    List<Movie> getMovieById(@Param("id") String id);

    @Select("SELECT * FROM booking WHERE cid = #{cid} AND mid = #{mid}")
    List<Booking> getBookingByCidAndMid(@Param("cid") String cid, @Param("mid") String mid);

    @Insert({
            "INSERT INTO orders (",
            "cname, murl, seat, hall, price, mname, day, time, state ,num",
            ") VALUES (",
            "#{cname}, #{murl}, #{seat}, #{hall}, #{price}, #{mname}, #{day}, #{time}, #{state},#{num}",
            ")"
    })
    void insertOrder(
            @Param("cname") String cname,
            @Param("murl") String murl,
            @Param("seat") String seat,
            @Param("hall") String hall,
            @Param("price") double price,
            @Param("mname") String mname,
            @Param("day") String day,
            @Param("time") String time,
            @Param("state") String state,
            @Param("num") int num
    );
}